import $ from 'jquery'
export const updateShoppingList = (context, {item, quantity, isAdd}) => {
    context.commit('updateShoppingList', {item, quantity, isAdd});
    if (isAdd) {
      let message_obj = {
        message: `成功添加 ${item.title} 到购物车`,
        messageClass: "success",
        autoClose: true
      }
      context.commit('addMessage', message_obj);
    }
}
export const removeItemShopping = (context, {item}) => {
    context.commit('removeGoodsItem', {item})
}
export function saveShopping() {
  // _, {id, shoppingItemList}
	// console.log("ACTIONS saveShoppingCart");
	// console.log("CART DATA", cartItemList);
	// return ref.child("cart/" + uid).set(cartItemList);
}

export function saveToTransaction(context, {shoppingItemList, id}) { 
    console.log(shoppingItemList)
    $.ajax({
      url: "http://127.0.0.1:8888/eshop/order/purchase",
      type: "post",
      contentType: 'application/json',
      data: JSON.stringify({
          shoppingItemList: shoppingItemList,
          id: id,
      }),
      success() {
          console.log('success to database')
      },
      error() {
          
      }
  })
  // _, {id, shoppingItemList}
	// let newTransactionKey = ref.child("transactions").push().key;
	// var newTransaction = {}
	// newTransaction['/transactions/' + uid + '/' + newTransactionKey] = cartItemList;
	// return ref.update(newTransaction);
}


